<?php
if (!function_exists('nv_block_thongbao')) {

    function nv_block_thongbao() {

        global $global_config, $site_mods, $db, $module_name, $global_array_cat,$lang_global;

        if ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/blocks/global.thongbao.tpl" ) )
        {
            $cp_block_theme = $global_config['module_theme'];
        }
        elseif ( file_exists( NV_ROOTDIR . "/themes/" . $global_config['site_theme'] . "/blocks/global.thongbao.tpl" ) )
        {
            $cp_block_theme = $global_config['site_theme'];
        }
        else
        {
            $cp_block_theme = "default";
        }
        
        $xtpl = new XTemplate("global.thongbao.tpl", NV_ROOTDIR . "/themes/" . $cp_block_theme . "/blocks");

        $sql_news_module = "SELECT `title`,`module_data` FROM `" . NV_PREFIXLANG . "_modules` WHERE `module_file` = 'news'";

        $news_modules = $db->sql_query($sql_news_module);
        while (list($cp_module_title, $cp_module_data) = $db->sql_fetchrow($news_modules)) {
            $sql = "SELECT id, listcatid, publtime, exptime, title, alias, homeimgthumb FROM `" . NV_PREFIXLANG . "_" . $cp_module_data . "_rows` WHERE `status`= 1 AND `publtime` < " . NV_CURRENTTIME . " AND (`exptime`=0 OR `exptime`>" . NV_CURRENTTIME . ") AND `is_notice`=1 ORDER BY `publtime` DESC LIMIT 0 , 10";
            $result = $db->sql_query($sql);

            $rows = array();
            while (list( $id, $listcatid, $publtime, $exptime, $title, $alias, $homeimgthumb ) = $db->sql_fetchrow($result)) {
                $catid = end(explode(",", $listcatid));

                $cp_find_category = "SELECT `alias` FROM `" . NV_PREFIXLANG . "_" . $cp_module_data . "_cat` WHERE `catid`=" . $catid . " LIMIT 1";
                $cp_cat_results = $db->sql_query($cp_find_category);
                list($cp_cat_alias) = $db->sql_fetchrow($cp_cat_results);
                if (!$cp_cat_alias) {
                    continue;
                }
                $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" .
                        NV_NAME_VARIABLE . "=" . $cp_module_title . "&amp;" .
                        NV_OP_VARIABLE . "=" . $cp_cat_alias . "/" . $alias . "-" . $id;
                $row['id'] = $id;
                $row['link'] = $link;
                $row['title'] = $title;
                $xtpl->assign("CONTENT", $row);
                $xtpl->parse("main.items");
            }
        }
        /*
          $sql = "SELECT id, listcatid, publtime, exptime, title, alias, homeimgthumb FROM `" . NV_PREFIXLANG . "_news_rows` WHERE `status`= 1 AND `publtime` < " . NV_CURRENTTIME . " AND (`exptime`=0 OR `exptime`>" . NV_CURRENTTIME . ") AND `is_notice`=1 ORDER BY `publtime` DESC LIMIT 0 , 10";
          $result = $db->sql_query($sql);

          $rows = array();
          while (list( $id, $listcatid, $publtime, $exptime, $title, $alias, $homeimgthumb ) = $db->sql_fetchrow($result)) {
          $catid = end( explode( ",", $listcatid ) );
          $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" .
          NV_NAME_VARIABLE . "=news&amp;" .
          NV_OP_VARIABLE . "=" . $global_array_cat[$catid]['alias'] . "/" . $alias . "-" . $id;
          $row['id'] = $id;
          $row['link'] = $link;
          $row['title'] = $title;
          $xtpl->assign("CONTENT", $row);
          $xtpl->parse("main.items");

          }
         */
        $xtpl->parse("main");
        return $xtpl->text("main");
    }

}
$content = nv_block_thongbao();
?>